package czk.concrent.threadstatus;

import java.util.concurrent.locks.LockSupport;

/**
 * @Author:ChenZhangKun
 * @Date: 2020/5/5 21:55
 */

/**
 * 打断park线程
 */
public class LockSupportTest {
    public static void main(String[] args) throws InterruptedException {
        test();
    }
    public static void test() throws InterruptedException {
        Thread thread=new Thread(()->{
            System.out.println("park");
            // 当打断标记为false时，才生效
            LockSupport.park();
            System.out.println("unpark");
            /**
             *  Thread.interrupted()不会改变线程的打断状态，调用后false，此时再调用part会生效
             *  Thread.currentThread().isInterrupted() 会改变线程的打断状态置为true,此时再执行part就不会生效
             */
            System.out.println("打断状态"+Thread.interrupted());
           // System.out.println(Thread.currentThread().isInterrupted());
            System.out.println("park");
            // 当打断标记为false时，才生效
            LockSupport.park();
            System.out.println("unpark");
        },"t1");
        thread.start();

        Thread.sleep(3*1000);

        thread.interrupt();
    }
}
